import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86131
 * Date: 2024-01-30
 * Time: 11:55
 */
public class Test3 {




    public static void main(String[] args) {
        //1.创建集合
        ArrayList<User> list = new ArrayList<>();

        //2.创建三个用户对象
        User u1 = new User("heima001","zhangsan","123456");
        User u2 = new User("heima002","lisi","123456");
        User u3 = new User("heima003","wangwu","123456");

        //3.把用户对象添加到集合中
        list.add(u1);
        list.add(u2);
        list.add(u3);

        //4.调用方法啊查看id是否存在
        boolean flag = contains(list, "heima005");
        //5.打印结果
        System.out.println(flag);

    }
    //1.我要干嘛     根据ID查找用户
    //2.干这件事需要什么才能完成     id list
    //3.调用处是否需要使用方法结果  返回
    public static boolean contains(ArrayList<User> list,String id) {
        for (int i = 0; i < list.size(); i++) {
            User u = list.get(i);
            String uId = u.getId();
            if (uId.equals(id)) {
                return true;
            }
        }

        //当循环结束表示集合所有的元素比较完毕,没有一样的
        return false;
    }
}
